package com.example.demo.controller;

import com.example.demo.entity.BookCategory;
import com.example.demo.entity.BookInfo;
import com.example.demo.service.BookCategoryService;
import com.example.demo.service.BookInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;
import java.awt.print.Book;
import java.util.List;

@Controller
public class IndexController {

@Autowired
private BookCategoryService bookCategoryService;

@Value("${book.categoryId}")
private String BOOK_CATEGORY;

@Autowired
private BookInfoService bookInfoService;

    @RequestMapping({"","/index","/","/index.html"})
    public String index(Model model, HttpServletRequest request){



        List<BookInfo> bookInfos=bookInfoService.selectAll();

        model.addAttribute("bookInfos",bookInfos);

    return "index";
    }

    @RequestMapping("/index/category/{id}")
    public String bookList(@PathVariable("id")Integer id,Model model){

        List<BookInfo> bookInfos=bookInfoService.selectByCatId(id);

        model.addAttribute("bookInfos",bookInfos);
        return "index";
    }




}
